package org.example.mapper.handle;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class EvaluateBaseInfoIsMultipleHandle implements TypeHandler<Boolean> {
    @Override
    public void setParameter(PreparedStatement ps, int i, Boolean parameter, JdbcType jdbcType) throws SQLException {
        System.out.println(String.format("索引: %s,参数值: %s ",i,parameter));
        ps.setInt(i,parameter?1:0);
    }

    @Override
    public Boolean getResult(ResultSet rs, String columnName) throws SQLException {
        System.out.println(String.format("列名: %s",columnName));
        return rs.getInt(columnName) == 1?true : false;
    }

    @Override
    public Boolean getResult(ResultSet rs, int columnIndex) throws SQLException {
        System.out.println(String.format("列索引: %s",columnIndex));
        return rs.getInt(columnIndex) == 1 ? true : false;
    }

    @Override
    public Boolean getResult(CallableStatement cs, int columnIndex) throws SQLException {

        return cs.getInt(columnIndex) == 1? true : false;

    }
}
